import * as moment from 'moment';

export const Guest: any = {
    name: 'Guest',
    admin: false
};

export class User {
    token: string;
    userInfo: any;
    expire: string;

    constructor(userInfo?, token?: string, expire?: string) {
        this.userInfo = userInfo || Guest;
        this.token = token || moment().format('YYYYMMDD');
        this.expire = expire || moment().add('hours', 1).format('YYYYMMDDHHmmss');
    }

    setExpire() {
        this.expire = moment().add('hours', 1).format('YYYYMMDDHHmmss');
    }

    isExpired() {
        const last = moment(this.expire, 'YYYYMMDDHHmmss');
        return moment().isAfter(last);
    }
}

export class Login {
    userName: string;
    pwd: string;
}